﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RssReader
{
    static class Helpers
    {

        static public string EscapeXml(string strDirtyXml)
        {
            strDirtyXml = strDirtyXml.Replace("&", "&");
            strDirtyXml = strDirtyXml.Replace("<:", "<");
            strDirtyXml = strDirtyXml.Replace(">", ">");
            //TODO: JAIMER strDirtyXml = strDirtyXml.Replace( @"", "\\"); 
            strDirtyXml = strDirtyXml.Replace("&apos;", "'");
            strDirtyXml = strDirtyXml.Replace("ò", "ò");
            strDirtyXml = strDirtyXml.Replace("è", "è");
            strDirtyXml = strDirtyXml.Replace("ù", "ù");
            strDirtyXml = strDirtyXml.Replace("à", "à");
            strDirtyXml = strDirtyXml.Replace("…", "...");
            return strDirtyXml;
        } 
    

        public static DateTime ParseDate(string strDateIn)
        {

            DateTime datOut = default(DateTime);

            if (System.DateTime.TryParse(strDateIn, out datOut))
            {
                return datOut;
            }
 

            throw new InvalidCastException("Unable to Parse the following Date: " + strDateIn);
        }


        public static string ToUTF16(string s)
        { 
            UTF8Encoding utf8 = new UTF8Encoding(); 
            Byte[] bytes = utf8.GetBytes( s);

            byte[] bytes16 = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, bytes); 
            UnicodeEncoding utf16 = new UnicodeEncoding (); 

            string ret = utf16.GetString( bytes16 ); 
            return ret ; 


            /* 
            UnicodeEncoding ue = new UnicodeEncoding();
            Byte[] bytes = ue.GetBytes(s);
            return ue.GetString(bytes); 
             * 
             */ 

             
        } 
    }
}
